<?php
class Bootstrap_FrontCtrl {		
	const DEFAULT_ACTION_HELPER_PREFIX = 'ActionHelper';
	
	static public function build()	{	
		//$config = Zend_Registry::get('config');				
		
		$frontCtrl = Zend_Controller_Front::getInstance();			
		$frontCtrl->throwExceptions(true);
		$frontCtrl->setParam('useDefaultControllerAlways', false);

		$frontCtrl->setControllerDirectory(APP_DIR.DIRECTORY_SEPARATOR.'default'.DIRECTORY_SEPARATOR.'controllers');
		$frontCtrl->addControllerDirectory(APP_DIR.DIRECTORY_SEPARATOR.'admin'.DIRECTORY_SEPARATOR.'controllers', 'admin');
		//setParam
		//$timeStart = microtime(true);
		//$frontCtrl->setParam('timeStart', $timeStart);
		
		if(!$frontCtrl->hasPlugin(ControllerPlugin_Acl::NAME)){
			try{
				$frontCtrl->registerPlugin(new ControllerPlugin_Acl());
			}catch (Exception $e){
				throw $e;
			}
		}	
		if(!$frontCtrl->hasPlugin(ControllerPlugin_Param::NAME)){
			try{
				$frontCtrl->registerPlugin(new ControllerPlugin_Param());
			}catch (Exception $e){
				throw $e;
			}
		}	
		
		//set actionHelper
		Zend_Controller_Action_HelperBroker::addPrefix(self::DEFAULT_ACTION_HELPER_PREFIX);
		
		$router = $frontCtrl->getRouter();
		$router->addRoute(
		    'user_blog_list',
		    new Zend_Controller_Router_Route(
		        'u/:u_id',
			    array(			        
			        'controller' => 'index',
			        'action'     => 'index',
			    	'module'     => 'default'
			    )
		    )
		);
		$router->addRoute(
		    'category_blog_list_1',
		    new Zend_Controller_Router_Route(
		        'u/:u_id/c/:c_id',
			    array(			        
			        'controller' => 'index',
			        'action'     => 'index',
			    	'module'     => 'default'
			    )
		    )
		);		
		$router->addRoute(
		    'user_blog_show',
		    new Zend_Controller_Router_Route(
		        'b/:b_id',
			    array(			        
			        'controller' => 'index',
			        'action'     => 'blog',
			    	'module'     => 'default'
			    )
		    )
		);
		return $frontCtrl;
	}
}